﻿<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../lib/html5shiv.js"></script>
    <script type="text/javascript" src="../lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <title>应用</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

</head>

<body>
    <article class="page-container">
        <form class="form form-horizontal" id="form-article-add">

            <div class="row cl" style="display:none;">
                <label class="form-label"><span class="c-red">*</span>ID标识：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="0" placeholder="" name="id" readonly>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">[外]项目ID</label>
                <div class="formControls">
                    <!-- <input type="number" class="input-number" value="" placeholder="命名空间" name="projectId"> -->
                    <select name="projectId">
                        <option value="0">待选择</option>
                    </select>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">服务代码</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" required maxlength="16"
                        placeholder="main/report/notify/mainapi..." name="code">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">名称</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" required maxlength="16" placeholder="示例：商城-订单系统"
                        name="name">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">存放路径</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" maxlength="128"
                        placeholder="一般留空，用于前端非规范存放路径的时候使用，比如需要嵌入到其他服务的路径内，一般用于静态文件模式,相对于spider来说的路径" name="directPath">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">服务描述</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" maxlength="128" placeholder="服务描述" name="desc">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">是否可用</label>
                <div class="formControls">
                    <input type="checkbox" class="input-checkbox" checked name="isEnable">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">当前版本</label>
                <div class="formControls">
                    <input type="number" class="input-number" value="1000" placeholder="当前版本" name="version">
                </div>
            </div>

            <div class="row cl" style="display:none">
                <label class="form-label">推送地址</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" maxlength="128" placeholder="推送地址"
                        name="configNotify">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">监听端口</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="80" maxlength="128" placeholder="80,443"
                        name="listenPorts">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">是否需要端口映射</label>
                <div class="formControls">
                    <input type="checkbox" class="input-checkbox" name="needMapping">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">文件模式</label>
                <div class="formControls">
                    <select name="fileModel">
                        <option value="0">静态文件，不需要发布</option>
                        <option value="1">源码模式，在服务端编译，构建和升级</option>
                        <option value="2" selected>发布模式，在服务端构建和升级</option>
                        <option value="3">镜像模式，直接使用镜像，不需要构建</option>
                    </select>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">镜像名称</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" maxlength="256"
                        placeholder="当文件模式为镜像模式的时候，这个值不能为空,比如redis:latest" name="directImage">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">自动重启</label>
                <div class="formControls">
                    <input type="checkbox" class="input-checkbox" checked name="autoRestart">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">升级前置命令</label>
                <div class="formControls">
                    <!-- <input type="text" class="input-text" value="" placeholder="升级前置命令" name="beforeCommands"> -->
                    <textarea placeholder="前置命令，一行一条命令" name="beforeCommands"></textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">后置命令</label>
                <div class="formControls">
                    <!-- <input type="text" class="input-text" value="" placeholder="升级后置命令" name="afterCommands"> -->
                    <textarea placeholder="后置命令,一行一条命令" name="afterCommands"></textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">升级拆分次数</label>
                <div class="formControls">
                    <input type="number" class="input-number" value="3" placeholder="升级拆分次数" name="updateSplits">
                </div>
            </div>
            <div class="row cl">

                <label class="form-label">镜像保存版本</label>
                <div class="formControls">
                    <input type="number" class="input-number" value="2" placeholder="镜像保存版本" name="saveNumber">
                </div>
            </div>
            <div class="row cl">

                <label class="form-label">其他参数</label>
                <div class="formControls">
                    <input type="text" class="input-text" value=""
                        placeholder="启动参数(示例：-p 12345:90 -v /datadir/:/datadir/)" name="otherArgs">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">环境参数</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="环境参数(示例：node server.js)"
                        name="environmentArgs">
                </div>
            </div>

            <div class="row cl styleadd">
                <label class="form-label">环境信息</label>
                <div class="formControls selectlist">
                    <ul class="areaenvironment">                        
                        <!-- <li value="default" class="selected">默认环境</li>
                        <li value="dev">开发环境</li>
                        <li value="prod">工厂环境</li> -->
                    </ul>
                </div>
            </div>

            <div class="row cl">
                <div class="rowbtn">
                    <button onClick="_funcAdd();" class="btn btn-primary radius" type="button">保存</button>
                </div>
            </div>
        </form>
    </article>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer /作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <script src="../lib/api.js"></script>


    <script type="text/javascript">
        var iseditemodel = false;
        $(function () {


            _apiget('/api/spider/code/multiple',false,function(cc,oo){
                $(".areaenvironment").html(oo);
            })

            //获取参数中的ID
            var userid = 0;

            var uidstr = _apigetquery("id");
            if (uidstr != null) {
                userid = parseInt(uidstr);
                iseditemodel = true;
                if (userid == 0) {
                    iseditemodel = false;
                }
            } else {

                iseditemodel = false;

            }

            _readproject(false);

            if (iseditemodel) {

                $(".styleadd").hide();

                _loaditem(userid);
            } else {
                $(".styleedit").hide();
            }

            $(".selectlist").on('click', 'li', function () {
                if ($(this).hasClass("selected")) {
                    $(this).removeClass("selected");
                } else {
                    $(this).addClass("selected");
                }
            })

        });

        function _loaditem(userid) {
            //读取角色列表
            _apiget("/api/spider/serviceInfo/" + userid + "/infoForUpdate", true, function (code, obj) {
                if (code == 200) {
                    _bindelement(obj);
                }
            });
        }

        function _funcAdd() {

            var dataobj = $("#form-article-add").parseForm();


            if (iseditemodel) {
                _apipost("/api/spider/serviceInfo/updateItem", true, JSON.stringify(dataobj), function (code, obj) {
                    if (code == 200) {
                        layer.msg("更新成功", { time: 1500 }, function () {
                            if (removeIframe) {
                                removeIframe();
                            }
                        });
                    }
                });
            } else {

                var elcs = $(".selectlist").find(".selected");
                var binds = new Array();
                elcs.each(x => {
                    var val = $(elcs[x]).attr("value");
                    binds.push((val));
                })
                dataobj.models = binds;

                if (dataobj.models.length == 0) {
                    layer.msg("请至少选择一个环境信息");
                }

                _apipost("/api/spider/serviceInfo/item", true, JSON.stringify(dataobj), function (code, obj) {
                    if (code == 200) {
                        layer.msg("添加成功");
                    }
                });
            }
        }
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>

</html>